package t7_concurrent.t1_pool;


import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author fanglingxiao
 * @version 1.0
 * @description TODO
 * @date 2022/5/8 4:15 下午
 **/
public class Test06_ThreadPoolExecutor {
    private static final ThreadFactory EXECUTOR_FACTORY = new ThreadFactoryBuilder().setNameFormat("fang-test-%s").build();
    private static final ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(
            8,
            10,
            1000,
            TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(1024),
            EXECUTOR_FACTORY,
            new ThreadPoolExecutor.AbortPolicy());

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            int temp = i;
            EXECUTOR.execute(() -> System.out.println(Thread.currentThread().getName() + "-" + temp));
        }
    }
}

